/**
 * order query
 */
package com.client.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.action.AbstractAction;
import com.auth.service.AccountService;
import com.auth.service.AccountServiceImpl;
import com.client.model.IPayData;
import com.client.model.IPayOrder;
import com.client.service.PayDataService;
import com.client.service.PayDataServiceImpl;
import com.manage.cache.ChannelManager;
import com.manage.cache.CpAppInfoManager;
import com.manage.cache.CpInfoManager;
import com.manage.cache.ProjectManager;
import com.manage.cache.SpCodeManager;
import com.manage.cache.SpInfoManager;
import com.manage.model.Channel;
import com.manage.model.CpAppInfo;
import com.manage.model.CpInfo;
import com.manage.model.Project;
import com.manage.model.SpCode;
import com.manage.model.SpInfo;
import com.util.Region;

/**
 * @author jinmei.wang
 *
 */
public class PayQueryAction extends AbstractAction {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String date1;
	private String date2;
	private List<Channel> channels;
	private List<Project> projects;
	private int plugin;
	private int channelId;
	private int projectId;
	private int cpId;
	private int cpId1;
	private int spId1;
	private int spCodeId1;
	private List<Region> regions;
	private String province1;
	private String region1;
	private List<SpInfo> spinfos;
	private List<SpCode> spCode;
	private String dimension;
	List<IPayData> list;
	List<IPayOrder> list1;
	private String mobile;
	private String orderId;
	private List<CpInfo> cpinfos;
	private List<CpAppInfo> appinfos;
	private String appnumber;
	
	public String query()
	{
		date1 = formatDate(new Date(), "yyyy-MM") + "-01";
		date2 = formatDate(new Date(), "yyyy-MM-dd");
		regions = getRegions("");
		channels = new ArrayList<Channel>();
		spinfos = new ArrayList<SpInfo>();
		cpinfos = CpInfoManager.getInstance().getCpInfos();
		appinfos = new ArrayList<CpAppInfo>();
		AccountService as = new AccountServiceImpl();
		List<Integer> spids = as.getAccountSp(operator.getId());
		if (spids != null)
		{
			for (SpInfo s : SpInfoManager.getInstance().getSpInfos())
			{
				if (spids.contains(s.getId()))
					spinfos.add(s);
			}
		}
		List<Integer> channelIds = as.getAccountChannel(operator.getId());
		if (channelIds != null)
		{
			for (Channel c : ChannelManager.getInstance().getChannels())
			{
				if (channelIds.contains(c.getId()))
					channels.add(c);
			}
		}
		projects = new ArrayList<Project>();
		for (Project p : ProjectManager.getInstance().getProjects())
		{
			if (channelIds.contains(p.getChannelId()))
				projects.add(p);
		}
		return SUCCESS;
	}
	public String oquery()
	{
		date1 = formatDate(new Date(), "yyyy-MM") + "-01";
		date2 = formatDate(new Date(), "yyyy-MM-dd");
		
		return SUCCESS;
	}
	public String odata()
	{
		PayDataService pdservice = new PayDataServiceImpl();
		list1 = pdservice.getPayOrder(date1, date2, mobile, orderId);
		return SUCCESS;
	}
	public String data()
	{
		PayDataService pdservice = new PayDataServiceImpl();
		list = pdservice.getPayDataByContent(date1, date2, channelId, projectId,
											spId1, spCodeId1, province1, region1, dimension, operator,cpId,appnumber);
		return SUCCESS;
	}
	public String changeprovince()
	{
		regions = getRegions(province1);
		return SUCCESS;
	}
	
	public String changechannel()
	{
		projects = ProjectManager.getInstance().getProjects(channelId);
		return SUCCESS;
	}
	
	public String changesp()
	{
		spCode = SpCodeManager.getInstance().getSpCodes(spId1, "");
		return SUCCESS;
	}
	public String changecp()
	{
		appinfos = CpAppInfoManager.getInstance().getCpAppInfos(cpId1);
		return SUCCESS;
	}
	
	public String getSpName(int spId)
	{
		return SpInfoManager.getInstance().getSpInfo(spId).getSpName();
	}
	public String getSpCodeName(int spCodeId)
	{
		return SpCodeManager.getInstance().getSpCode(spCodeId).getCodeName();
	}
	public String getChannelName(int channelId)
	{
		return ChannelManager.getInstance().getChannel(channelId).getName();
	}
	public String getProjectName(int projectId)
	{
		return ProjectManager.getInstance().getProject(projectId).getName();
	}
	 
	
	public String getAppName(String appid)
	{
		return CpAppInfoManager.getInstance().getCpAppInfoByAppNumber(appid).getAppname();
	}
	
	public String getCpName(int cpid)
	{
		CpInfo cp = CpInfoManager.getInstance().getCpInfo(cpid);
		if(cp!=null)
		{
			return cp.getCpName();
		}
		else{
			return "未知";
		}
	}
	
	
	public String getAppnumber() {
		return appnumber;
	}
	public void setAppnumber(String appnumber) {
		this.appnumber = appnumber;
	}
	public int getCpId() {
		return cpId;
	}
	public void setCpId(int cpId) {
		this.cpId = cpId;
	}
	public List<CpInfo> getCpinfos() {
		return cpinfos;
	}
	public void setCpinfos(List<CpInfo> cpinfos) {
		this.cpinfos = cpinfos;
	}
	public List<CpAppInfo> getAppinfos() {
		return appinfos;
	}
	public void setAppinfos(List<CpAppInfo> appinfos) {
		this.appinfos = appinfos;
	}
	public String getDate1() {
		return date1;
	}
	public void setDate1(String date1) {
		this.date1 = date1;
	}
	public String getDate2() {
		return date2;
	}
	
	public int getSpId1() {
		return spId1;
	}
	public void setSpId1(int spId1) {
		this.spId1 = spId1;
	}
	public int getSpCodeId1() {
		return spCodeId1;
	}
	public void setSpCodeId1(int spCodeId1) {
		this.spCodeId1 = spCodeId1;
	}
	public String getProvince1() {
		return province1;
	}
	public void setProvince1(String province1) {
		this.province1 = province1;
	}
	public String getRegion1() {
		return region1;
	}
	public void setRegion1(String region1) {
		this.region1 = region1;
	}
	public void setDate2(String date2) {
		this.date2 = date2;
	}
	public List<Channel> getChannels() {
		return channels;
	}
	public void setChannels(List<Channel> channels) {
		this.channels = channels;
	}
	public List<Project> getProjects() {
		return projects;
	}
	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}
	public int getChannelId() {
		return channelId;
	}
	public void setChannelId(int channelId) {
		this.channelId = channelId;
	}
	public List<Region> getRegions() {
		return regions;
	}
	public void setRegions(List<Region> regions) {
		this.regions = regions;
	}
	
	public List<SpInfo> getSpinfos() {
		return spinfos;
	}
	public void setSpinfos(List<SpInfo> spinfos) {
		this.spinfos = spinfos;
	}
	
	public List<SpCode> getSpCode() {
		return spCode;
	}
	public void setSpCode(List<SpCode> spCode) {
		this.spCode = spCode;
	}
	public int getProjectId() {
		return projectId;
	}
	public void setProjectId(int projectId) {
		this.projectId = projectId;
	}

	public String getDimension() {
		return dimension;
	}
	public void setDimension(String dimension) {
		this.dimension = dimension;
	}

	public List<IPayData> getList() {
		return list;
	}
	public void setList(List<IPayData> list) {
		this.list = list;
	}
	/**
	 * @return the plugin
	 */
	public int getPlugin() {
		return plugin;
	}
	/**
	 * @param plugin the plugin to set
	 */
	public void setPlugin(int plugin) {
		this.plugin = plugin;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getOrderId() {
		return orderId;
	}
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	public List<IPayOrder> getList1() {
		return list1;
	}
	public void setList1(List<IPayOrder> list1) {
		this.list1 = list1;
	}
	public int getCpId1() {
		return cpId1;
	}
	public void setCpId1(int cpId1) {
		this.cpId1 = cpId1;
	}
	
	
}
